//
//  Enhance.swift
//  learn-gl-es-swift
//
//  Created by LimitLiu on 2019/7/1.
//  Copyright © 2019 LimitLiu. All rights reserved.
//

import GLKit

extension Array {
    func sizeof() -> Int {
        return self.count > 0 ? self.count * MemoryLayout.size(ofValue: self[0]) : 0
    }
}

extension GLKEffectPropertyTexture {
    func set(parameterId: GLenum, value: GLint) -> Void {
        glBindTexture(target.rawValue, name)
        glTexParameteri(target.rawValue, parameterId, value)
    }
}

extension GLKMatrix4 {
    var array: [Float] {
        return (0..<16).map { self[$0] }
    }
}

extension GLKMatrix3 {
    var array: [Float] {
        return (0..<9).map { self[$0] }
    }
}

extension GLKTextureInfo {
    var getTarget: GLKTextureTarget {
        return GLKTextureTarget(rawValue: target)!
    }
}

func vec(_ x: Float, _ y: Float, _ z: Float) -> GLKVector3 {
    return GLKVector3Make(x, y, z)
}

func vec(_ x: Float, _ y: Float) -> GLKVector2 {
    return GLKVector2Make(x, y)
}

func vec(_ x: Float, _ y: Float, _ z: Float, _ w: Float) -> GLKVector4 {
    return GLKVector4Make(x, y, z, w)
}
